<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="dice">
    <meta name="author" content="weina">
    <title>home list</title>
    <link rel="stylesheet" href="/css/bootstrap.css">
    <link rel="stylesheet" href="/css/select2.min.css">
    <script src="/js/jquery-3.3.1.min.js"></script>
    <script src="/js/bootstrap.js"></script>
    <script src="/js/select2.min.js"></script>
</head>
<body>
<div class="container" style="margin-top: 100px">
    <a href="openRoom" style="margin-bottom: 40px">create room</a>
    <table class="table table-hover">
        <thead>
        <tr>
            <th>#</th>
            <th>room Number</th>
            <th>player Count</th>
            <th>room Owner Name</th>
            <th>operate</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="room,roomStat : ${rooms}">
            <th scope="row" th:text="${roomStat.index}+1"></th>
            <td th:text="${room.roomNumber}">roomNumber</td>
            <td th:text="${room.playerCount}">playerCount</td>
            <td th:text="${room.roomOwnerName}">roomOwnerName</td>
            <td><a th:href="@{'roomDetail?roomNumber='+${room.roomNumber}}"/>operate | <a
                    th:onclick="@{'javascript:delRoom('+${room.roomNumber}+')'}">delete</a></td>
        </tr>
        </tbody>
    </table>
</div>
<script type="text/javascript">
    function delRoom(roomNumber) {
        var param = {"roomNumber": roomNumber};
        $.ajax({
            type: "POST",
            url: "/room/delRoom",
            data: param,
            dataType: "json",
            success: function (data) {
                if (data.result === "success" && data.bizCode==="E_0000") {
                    alert("delete room success")
                    location.href = "roomList";
                } else {
                    alert(data.bizMsg);
                }
            }
        });
    }
</script>
</body>
</html>